#!/usr/bin/env python
# -*- coding:utf-8 -*-

# file:09操作mysql数据库插入数据.py
# author: 马国鑫
# datetime:2022/4/17 21:59
# software: PyCharm

"""
this is function  description 
"""

# import module your need

import pymysql
conn = pymysql.connect(host='localhost', user='root',
                       password='021207', database='python_db', port=3306)

cur = conn.cursor()

# 执行sql
try:
    sql = 'insert into t_student(sname, age, score) values (%s,%s,%s)'
    cur.execute(sql, ('马国鑫', 19, 99.9))
    conn.commit()
    print('插入成功')
except Exception as e:
    print(e)
    conn.rollback()
    print('插入失败')
finally:
    cur.close()
    conn.close()
